home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F39856_elimError.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-02-06  |  4.9 KB  |  146 lines

  1. <xsl:stylesheet version="1.0" 
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xalan="http://xml.apache.org/xalan"
  4. xmlns:math="xalan://java.lang.Math"
  5. exclude-result-prefixes="xsl xalan math"
  6. >
  7.  
  8.   <xsl:variable name="vLn-2" select="0.69314718056"/>  
  9.   <xsl:template name="elimError">
  10.     <xsl:param name="pList" select="/.."/>
  11.     <xsl:param name="pOrder" select="-9999999"/>
  12.     <xsl:param name="pv2__N" select="0"/>
  13.     
  14.     <xsl:choose>
  15.       <xsl:when test="count($pList) < 3">
  16.         <xsl:copy-of select="$pList"/>
  17.       </xsl:when>
  18.       <xsl:otherwise>
  19.         <xsl:variable name="vOrder">
  20.             <xsl:choose>
  21.               <xsl:when test="$pOrder < -9999998">
  22.                 <xsl:call-template name="getOrder">
  23.                   <xsl:with-param name="pList" select="$pList"/>
  24.                 </xsl:call-template>
  25.               </xsl:when>
  26.               <xsl:otherwise>
  27.                 <xsl:value-of select="$pOrder"/>
  28.               </xsl:otherwise>
  29.             </xsl:choose>
  30.         </xsl:variable> 
  31.       
  32.         <xsl:variable name="v2__N">
  33.           <xsl:choose>
  34.               <xsl:when test="$pv2__N = 0">
  35.                   <xsl:call-template name="pow">
  36.                     <xsl:with-param name="base" select="2"/>
  37.                     <xsl:with-param name="pow" select="$vOrder"/>
  38.                   </xsl:call-template>
  39.               </xsl:when>
  40.               <xsl:otherwise>
  41.                   <xsl:value-of select="$pv2__N"/>
  42.               </xsl:otherwise>
  43.           </xsl:choose>
  44.         </xsl:variable>
  45.         
  46.         <xsl:element name="{name($pList[1])}">
  47.           <xsl:value-of select="($pList[2] * $v2__N - $pList[1]) 
  48.                                  div 
  49.                                   ($v2__N - 1)"/>
  50.         </xsl:element>
  51.         
  52.         <xsl:variable name="vNewList" select="$pList[position() > 1]"/>
  53.         
  54.         <xsl:variable name="vNewOrder">
  55.             <xsl:call-template name="getOrder">
  56.               <xsl:with-param name="pList" select="$vNewList"/>
  57.             </xsl:call-template>
  58.         </xsl:variable> 
  59.         <xsl:call-template name="elimError">
  60.             <xsl:with-param name="pList" select="$vNewList"/>
  61.             <xsl:with-param name="pOrder" select="$vNewOrder"/>
  62.             <xsl:with-param name="pv2__N" select="$v2__N"/>
  63.         </xsl:call-template>
  64.         
  65.       </xsl:otherwise>
  66.     </xsl:choose>
  67.   </xsl:template>
  68.   
  69.   <xsl:template name="getOrder">
  70.     <xsl:param name="pList" select="/.."/>
  71.     
  72.     <xsl:choose>
  73.       <xsl:when test="count($pList) < 3">1</xsl:when>
  74.       <xsl:otherwise>
  75.         <xsl:variable name="v1" select="($pList[1] - $pList[3])
  76.                                        div 
  77.                                          ($pList[2] - $pList[3])
  78.                                          - 1"/>
  79.         <xsl:variable name="v2">
  80.           <xsl:choose>
  81.             <xsl:when test="$v1 > 0">
  82.               <xsl:value-of select="$v1"/>
  83.             </xsl:when>
  84.             <xsl:when test="$v1 < 0">
  85.               <xsl:value-of select="(-1) * $v1"/>          
  86.             </xsl:when>
  87.             <xsl:otherwise>1</xsl:otherwise>
  88.           </xsl:choose>
  89.         </xsl:variable>
  90.         
  91.         <xsl:call-template name="roundLog2">
  92.           <xsl:with-param name="pX" select="string($v2)"/>
  93.         </xsl:call-template>
  94.       </xsl:otherwise>
  95.     </xsl:choose>
  96.   </xsl:template>
  97.   
  98.   <xsl:template name="roundLog2">
  99.     <xsl:param name="pX"/>
  100.     
  101.     <xsl:value-of select="math:round(math:log($pX) div $vLn-2)"/>
  102.   </xsl:template>
  103.   
  104.    <xsl:template name="pow">
  105.         <xsl:param name="base" select="1"/>
  106.         <xsl:param name="pow" select="0"/>
  107.         <xsl:param name="tmpResult" select="1"/>
  108.  
  109.         <xsl:variable name="result">
  110.             <xsl:choose>
  111.                 <xsl:when test="$pow >= 0">
  112.                     <xsl:value-of select="$tmpResult * $base"/>
  113.                 </xsl:when>
  114.                 <xsl:otherwise>
  115.                     <xsl:value-of select="$tmpResult div $base"/>
  116.                 </xsl:otherwise>
  117.            </xsl:choose>
  118.         </xsl:variable>
  119.  
  120.         <xsl:variable name="incr">
  121.             <xsl:choose>
  122.                 <xsl:when test="$pow >= 0">
  123.                     <xsl:value-of select="- 1"/>
  124.                 </xsl:when>
  125.                 <xsl:otherwise>
  126.                     <xsl:value-of select="1"/>
  127.                 </xsl:otherwise>
  128.             </xsl:choose>
  129.         </xsl:variable>
  130.  
  131.         <xsl:choose>
  132.             <xsl:when test="$pow = 0">
  133.                 <xsl:value-of select="$tmpResult"/>
  134.             </xsl:when>
  135.             <xsl:otherwise>
  136.                 <xsl:call-template name="pow">
  137.                     <xsl:with-param name="base" select="$base"/>
  138.                     <xsl:with-param name="pow" select="$pow + $incr"/>
  139.                     <xsl:with-param name="tmpResult" select="$result"/>
  140.                 </xsl:call-template>
  141.             </xsl:otherwise>
  142.         </xsl:choose>
  143.     </xsl:template>
  144.   
  145. </xsl:stylesheet>
  146.